﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms
{
    class MyLib
    {
        public static double CalculateMedian(params int[] pNumbers)
        {
            int len = pNumbers.Length;
            if (len == 0)
                throw new System.ArgumentException("No data");

            int size = pNumbers.Length;
            int mid = size / 2;
            double median = (size % 2 != 0) ? (double)pNumbers[mid] :
            ((double)pNumbers[mid] + (double)pNumbers[mid - 1]) / 2;
            return median;
        }

        public static double CalculateMean(params int[] data)
        {
            int len = data.Length;
            if (len == 0)
                throw new System.ArgumentException("No data");

            double sum = 0;
            for (int i = 0; i < data.Length; i++)
                sum += data[i];
            return sum / len;
        }

        public static int CalculateMin(params int[] rest)
        {
            int min = rest[0];
            foreach (int next in rest)
            {
                min = Math.Min(min, next);
            }
            return min;
        }

        public static int CalculateMax(params int[] rest)
        {
            int max = rest[0];
            foreach (int next in rest)
            {
                max = Math.Max(max, next);
            }
            return max;
        }

    }
}
